package com.changgou.search.controller;

import com.changgou.search.service.SkuService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/search")
public class SkuController {

    @Autowired
    private SkuService skuService;


    /**
     * 将数据导入索引库
     *
     * @return
     */
    @RequestMapping("/import")
    public Result importEs() {
        skuService.importDate();
        return new Result(true, StatusCode.OK, "导入成功");
    }


    /**
     *  required =false  允许为空
     * @param searchMap
     * @return
     */
    @GetMapping
    public Map search(@RequestParam(required = false) Map<String, String> searchMap) {
        return skuService.search(searchMap);
    }
}
